def use_dict1():
    xiaoming_dict = {'name':'小明'
                ,'age':18
                ,'height':1.8
                ,'gender':'man'}

    print(id(xiaoming_dict))
    # 打印某一值
    print(xiaoming_dict['name'])

    # 若key不存在，会增加
    xiaoming_dict['weight']=50

    # 若key已存在，会修改
    xiaoming_dict['name']='小小明'
    print(xiaoming_dict)

    # 删除pop,返回值是pop的元素,类似“弹出”
    # xiaoming_dict.pop('height')
    # print(xiaoming_dict.pop('height'))

    # del无返回值
    del xiaoming_dict['name']
    print(xiaoming_dict)

    #统计键值对数量
    print(len(xiaoming_dict))

    #合并字典
    temp_dict = {'height':1.75
                 ,'age':20}
    xiaoming_dict.update(temp_dict)
    print(xiaoming_dict)

    # 清空字典
    xiaoming_dict.clear()
    print(xiaoming_dict)

    print(id(xiaoming_dict))  # 地址未改变



def use_dict2():
    # 重新给字典赋值,地址会改变
    xiaoming_dict = {'name': '小明'
        , 'age': 18
        , 'height': 1.8
        , 'gender': 'man'}
    # 输出k只是key，而非key的值   字典.keys()或省略.keys()只遍历键
    for k in xiaoming_dict:
        print(k,xiaoming_dict[k])
    print('*'*50)

    # 字典.items()遍历所有(key,value)元组列表
    for kv in xiaoming_dict.items():
        print(kv)
    for k,v in xiaoming_dict.items():
        print(f'key:{k} value:{v}')

    # 字典.values()遍历所有value值
    for v in xiaoming_dict.values():
        print(v)

    print(id(xiaoming_dict))  # 地址改变


#拆包
def use_unpack_package():
    k,v,w=1,2,3
    print(k,v,w)



if __name__ == '__main__':
    xiaoming_dict = {'name': '小明'
        , 'age': 18
        , 'height': 1.8
        , 'gender': 'man'}
    # use_dict1()
    # use_dict2()
    use_unpack_package()


